<template>
  <div id="app">
    <app-header :seller="seller"></app-header>
    <div class="tab border-1px">
      <router-link to="/goods" tag="div">商品</router-link>
      <router-link to="/ratings" tag="div">评论</router-link>
      <router-link to="/seller" tag="div">商家</router-link>
    </div>
    <keep-alive>
      <router-view :seller="seller"></router-view>
    </keep-alive>
  </div>
</template>

<script type="text/ecmascript-6">
  import header from 'components/header/header.vue';
  import {urlParam} from './common/js/util.js';

  const ERR_OK = 0;

  export default {
    data() {
      return {
        seller: {
          // 商家id 从url参数中取得
          id: (() => {
            let queryParam = urlParam();
            // console.log(queryParam);
            return queryParam.id;
          })()
        }
      };
    },
    created() {
      this.$http.get('/api/seller?id=' + this.seller.id).then((response) => {
        response = response.body;
        // console.log(response);
        if (response.errno === ERR_OK) {
          // this.seller = response.data;
          this.seller = Object.assign({}, this.seller, response.data);
        }
      });
    },
    components: {
      'app-header': header
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus">
@import "./common/stylus/mixin.styl"
  #app
    .tab
      display flex
      width 100%
      height 40px
      line-height 40px
      border-1px(rgba(7, 17, 27, .1))
      div
        flex 1
        text-align center
        cursor pointer
        font-size 14px
        color rgb(77, 85, 93)
        &.active
          color rgb(240, 20, 20)
</style>
